<!-- 所有审批列表页 新增班组、离场、调岗、班组长变更 & 实名认证、进场 & 补卡 -->
<template>
	<view class="content">
        <u-navbar :fixed="true" :safeAreaInsetTop="true" :placeholder="true"
            @leftClick="back" :title="jurisdiction.title">
        </u-navbar>
        <view class="uni-shadow u-p-0" style="border:none">
            <u-subsection bgColor="#fff" fontSize="14" :list="tab" :current="current" @change="change"></u-subsection>
        </view>

        <swiper class="uni-area swiper" :style="{height:swiperH+'px'}" :current="current" @change="change">
            <swiper-item>
                <scroll-view :scroll-y="current==0" :style="{height:swiperH+'px'}" 
                    :scroll-top="page.scrollTop" @scroll="scroll" :lower-threshold="0" @scrolltolower="scrollBottom">
                    <uni-item-examine class="u-m-t-30" v-for="(tem,ind) in page.list" :key="ind" :tem="tem"
                        @examineDetail="examineDetail(tem.id)">
                    </uni-item-examine>
                    <!-- 返回顶部 -->
                    <u-back-top :scroll-top="page.scrollTop" top="600" @tap="toTop"></u-back-top>
                    <!-- 加载更多 -->
                    <u-loadmore :status="page.status"/>
                    <!-- 间隙 -->
                    <u-gap class="u-m-t-10" height="10rpx" bgColor="#FBFCFC"></u-gap>
                </scroll-view>
            </swiper-item>
            <swiper-item>
                <scroll-view :scroll-y="current==1" :style="{height:swiperH+'px'}" 
                    :scroll-top="page.scrollTop" @scroll="scroll" :lower-threshold="0" @scrolltolower="scrollBottom">
                    <uni-item-examine class="u-m-t-30" v-for="(tem,ind) in page.list" :key="ind" :tem="tem"
                        @examineDetail="examineDetail(tem.id)">
                    </uni-item-examine>
                    <!-- 返回顶部 -->
                    <u-back-top :scroll-top="page.scrollTop" top="600" @tap="toTop"></u-back-top>
                    <!-- 加载更多 -->
                    <u-loadmore :status="page.status" />
                    <!-- 间隙 -->
                    <u-gap class="u-m-t-10" height="10rpx" bgColor="#FBFCFC"></u-gap>
                </scroll-view>
            </swiper-item>
        </swiper>
	</view>
</template>

<script>
	export default {
		data() {
			return {
                userInfo: uni.getStorageSync('userInfo'),
                swiperH: 700,
                jurisdiction:{
                    type: 'autonym', 
                    title: '实名制审批', 
                    item: {},
                },
				tab:['代办任务', '已办任务'],
                current: 0,
                parameter:{ 
                    deptId: uni.getStorageSync("userInfo").deptId, // 部门编号
                    gcbh: uni.getStorageSync("userInfo").ssgcbh // 项目编号
                },
                paging:{
                    pageNum: 1,
                    pageSize: this.$config.pageSize,
                },
                page:{
                    scrollTop: 0,
                    status: 'loadmore',
                    total: 0,
                    list: [],
                },
			}
		},

        mounted(){
            this.swiperH = uni.$u.sys().windowHeight - uni.$u.sys().statusBarHeight - 44 - uni.upx2px(84)
        },

		onLoad(option) {
            this.jurisdiction.type = option.type
            switch (option.type) {
                case 'team':
                    this.jurisdiction.title = '新增班组审批' // title
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API
                    this.jurisdiction.toDoPar = { procDefKey:'salary_smzgl_xmbz'} // 代办部分参数
                    this.jurisdiction.doneApi = this.$apis.ywAddGroupList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    this.jurisdiction.item = [ // 展示的字段
                        { field:'deptName', title:'所属单位', value:'安薪乐' },
                        { field:'bzmc', title:'班组名称', value:'安薪乐' },
                        { field:'createUser', title:'申请人', value:'安薪乐' },
                        { field:'createTime', title:'申请日期', value:'安薪乐' },
                        { field:'id', title:'业务编号', value:'安薪乐' },
                        { field:'ywzt', title:'业务状态', value:'安薪乐' },
                    ]
                    break;
                case 'leave':
                    this.jurisdiction.title = '人员离场审批' // title
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API
                    this.jurisdiction.toDoPar = { procDefKey:'salary_smzgl_rylc'} // 代办部分参数
                    this.jurisdiction.doneApi = this.$apis.memberLeaveList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    this.jurisdiction.item = [ // 展示的字段
                        { field: 'deptName', title:'所属单位' , value:'张三、李四、王五' },
                        { field: 'lcrs', title:'离场人数' , value:'男' },
                        { field: 'lcsj', title:'离场时间' , value:'513701192145251218' },
                        { field: 'createUser', title:'申请人' , value:'某某班组' },
                        { field: 'createTime', title:'申请日期' , value:'某某班组' },
                        { field: 'id', title:'业务编号' , value:'某某班组' },
                        { field: 'ywzt', title:'业务状态' , value:'待审核' },
                    ]
                    break;
                case 'transfer':
                    this.jurisdiction.title = '人员调岗审批' // title
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API  
                    this.jurisdiction.toDoPar = { procDefKey:'salary_smzgl_modifygroup'} // 代办部分参数
                    this.jurisdiction.doneApi = this.$apis.memberTransferList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    this.jurisdiction.item = [ // 列表展示字段
                        { field: 'deptName', title:'所属单位' , value:'安薪乐' },
                        { field: 'groupname', title:'班组名称' , value:'安薪乐' },
                        { field: 'groupleadername', title:'班组长姓名' , value:'安薪乐' },
                        { field: 'createUser', title:'申请人' , value:'安薪乐' },
                        { field: 'createTime', title:'申请日期' , value:'安薪乐' },
                        { field: 'id', title:'业务编号' , value:'安薪乐' },
                        { field: 'ywzt', title:'业务状态' , value:'待审核' },
                    ]
                    break;
                case 'foreman': 
                    this.jurisdiction.title = '班组长变更审批'
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API
                    this.jurisdiction.toDoPar = { procDefKey:'salary_bzz_change'} // 代办部分参数
                    this.jurisdiction.doneApi = this.$apis.groupChangeList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    this.jurisdiction.item = [
                        { field: 'deptName', title:'所属单位' , value:'王五' },
                        { field: 'bzmc', title:'班组名称' , value:'男' },
                        { field: 'createUser', title:'申请人' , value:'513701192145251218' },
                        { field: 'createTime', title:'申请日期' , value:'张三' },
                        { field: 'id', title:'业务编号' , value:'男' },
                        { field: 'ywzt', title:'业务状态' , value:'班组名称' },
                    ]
                    break;
                case 'autonym':
                    this.jurisdiction.title = '实名制审批' // title
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API
                    this.jurisdiction.toDoPar = { procDefKey:'salary_smzgl_ryxx_smrz'} // 代办部分参数
                    this.jurisdiction.doneApi = this.$apis.autonymList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    this.jurisdiction.item = [
                        { field: 'xm', title:'姓名' , value:'安薪乐' },
                        { field: 'zjhm', title:'公民身份号码' , value:'110101197001010001' },
                        { field: 'deptName', title:'所属单位' , value:'安薪乐' },
                        { field: 'bzmc', title:'班组名称' , value:'安薪乐' },
                        { field: 'createUser', title:'申请人' , value:'安薪乐' },
                        { field: 'createTime', title:'申请时间' , value:'1970-01-01' },
                        { field: 'id', title:'业务编号' , value:'1970-01-01' },
                        { field: 'ywzt', title:'业务状态' , value:'待审核' },
                    ]
                    break;
                case 'enter':
                    this.jurisdiction.title = '人员进场审批' // title
                    this.jurisdiction.toDoApi = this.$apis.examineTodoList // 代办API         
                    this.jurisdiction.toDoPar = { procDefKey:'salary_smzgl_pqxx'} // 代办部分参数
                    this.jurisdiction.item = [ // 展示的字段
                        { field: 'deptName', title:'所属单位' , value:'王五' },
                        { field: 'pqrs', title:'派遣人数' , value:'男' },
                        { field: 'pqrq', title:'派遣时间' , value:'513701192145251218' },
                        { field: 'createUser', title:'申请人' , value:'班组名称' },
                        { field: 'createTime', title:'申请日期' , value:'班组名称' },
                        { field: 'id', title:'业务编号' , value:'班组名称' },
                        { field: 'ywzt', title:'业务状态' , value:'待审核' },
                    ],
                    this.jurisdiction.doneApi = this.$apis.enterList // 已办API
                    this.jurisdiction.donePar = Object.assign( {sfyx:1, ywzt:0, spzt:0},this.parameter ) // 已办部分参数
                    break;
                case 'buka':
                    this.jurisdiction.title = '补卡审批' // title
                    this.jurisdiction.toDoApi = this.$apis.makeCardList // 代办API
                    this.jurisdiction.toDoPar = { deptId:this.userInfo.deptId, sfyx:1, ywzt:3, spzt:2, xmbh:this.userInfo.ssgcbh, gcbh:this.userInfo.ssgcbh } // 代办参数
                    this.jurisdiction.doneApi = this.$apis.makeCardList // 已办API
                    this.jurisdiction.donePar = { deptId:this.userInfo.deptId, sfyx:1, ywzt:0, spzt:0, xmbh:this.userInfo.ssgcbh, gcbh:this.userInfo.ssgcbh } // 已办参数
                    this.jurisdiction.item = [ // 列表展示字段
                        { field:'xm', title:'姓名', value:'安薪乐' },
                        { field:'zjhm', title:'公民身份号码', value:'安薪乐' },
                        { field:'bksj', title:'补卡时间', value:'安薪乐' },
                        { field:'bklx', title:'补卡类型', value:'安薪乐' },
                        { field:'dept_name', title:'所属单位', value:'安薪乐' }, // deptName
                        { field:'bzmc', title:'班组名称', value:'安薪乐' },
                        { field:'update_user', title:'申请人', value:'安薪乐' }, // createUser
                        { field:'CREATE_TIME', title:'申请日期', value:'安薪乐' }, // createTime
                        { field:'id', title:'业务编号', value:'安薪乐' },
                        { field:'ywzt', title:'业务状态', value:'安薪乐' },
                    ]
                    break;
            }
        },

        onShow(){
            // 审批列表
            this.paging.pageNum = 1
            this.page.list = []
            this.getList()
        },

		methods: {
            back(){
                uni.navigateBack()
            },

            // tab切换&页面左右滑动事件
            change(e){
                const index = e.detail?e.detail.current:e
                if( this.current != index ){   
                    this.current = index
                    this.paging.pageNum = 1
                    this.page.list = []
                    this.getList()
                    this.toTop()
                }
            },

            // 获取审批列表
            getList(){
                this.page.status = 'loading'
                let api, parameter
                if( this.current == 0 ){
                    api = this.jurisdiction.toDoApi
                    parameter = Object.assign(this.jurisdiction.toDoPar,this.paging)
                }else{ 
                    api = this.jurisdiction.doneApi
                    parameter = Object.assign(this.jurisdiction.donePar,this.paging)
                }
                // console.log('参数',parameter)
                this.$request(this,api,parameter).then(res=>{
                    this.page.total = res.total
                    const rows = res.rows ? res.rows : res.data
                    console.log(this.current?'已办列表':'代办列表',rows)
                    if( rows.length ){
                        this.page.status = 'loadmore'
                        rows.map((v,i)=>{
                            const temporaryData = JSON.parse(JSON.stringify(this.jurisdiction.item))
                            temporaryData.map((a,b)=>{
                                if( a.field =='ywzt' ) {
                                    a.value = v.ywzt==0?'办结':v.ywzt==1?'临时':v.ywzt==2?'注销':v.ywzt==3?'办理中':'签收中'
                                }else if( a.field =='zjhm' ){
                                    a.value = this.$tools.formatIdentity(v[a.field])
                                }else if( a.field == 'bklx' ){
                                    a.value = v[a.field]==1?'进场':'离场'
                                }else{
                                    a.value = v[a.field]?v[a.field]:'暂无数据源'
                                }
                            })
                            this.page.list.push({
                                id: v.id,
                                checked: false,
                                list: temporaryData,
                            })
                        })
                    }else{
                        this.page.status = 'nomore'
                        uni.$u.toast('暂未查询到更多审核相关数据')
                    }
                }).then()
            },
            // 查看审批详情
            examineDetail(id){
                uni.navigateTo({ url: '/pages/examine-bag/detail?status='+this.current+'&type='+this.jurisdiction.type+'&id='+id })
            },

            // 滚动
            scroll(e) {
                this.page.scrollTop = e.detail.scrollTop
            },
            // 滚动到底部
            scrollBottom(){
                if( this.page.list.length < this.page.total ){
                    this.paging.pageNum ++
                    this.getList()
                }else{
                    this.page.status = 'nomore'
                }
            },
            // 返回顶部
            toTop(){
                this.page.scrollTop = 0
            }
		}
	}
</script>

<style lang="scss">
    .content{
        .swiper{
            .item{
                padding: 20rpx 0;
                border-bottom: 1rpx solid #eee;
                &:last-child{
                    border: none;
                }
            }
        }
    }
</style>
